package com.xm.xmapp.adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.xm.xmapp.R;
import com.xm.xmapp.base.MyBaseAdapter;
import com.xm.xmapp.base.ViewHolder;
import com.xm.xmapp.response.bean.ResponseAccountRecord;
import com.xm.xmapp.tools.StringTools;

public class AccountRecordAdapter extends MyBaseAdapter<ResponseAccountRecord> {

	public AccountRecordAdapter(ArrayList<ResponseAccountRecord> list, Activity context, int layoutId) {
		super(list, context, layoutId);

	}

	@Override
	public void setValues(ViewHolder holder, final ResponseAccountRecord t, int position) {

		// process_type 操作类型:1=充值,2=退款，3=扣款，4=支付租车，5=活动，6=后台充值，7=违章处理，8=其他
		// process_type 操作类型:1=充值,2=退款，3=扣款，4=支付租车，5=活动，6=后台充值，7=违章处理，8=其他
		// payment_type
		// 支付方式:1=微信公众号支付，2=支付宝支付，3=网银,4=现金，5=钱包，6=微信app支付，7=活动,8=充值卡

		holder.setText(R.id.text, t.money_user_way_text);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日   HH:mm:ss     ");
		Date curDate = new Date(t.add_time * 1000);
		// 获取当前时间
		String str = formatter.format(curDate);
		holder.setText(R.id.text1, str);

		TextView text = null;

		if (t.is_success == 1) {
			text = (TextView) holder.getView(R.id.text2);
			holder.getView(R.id.lin).setVisibility(View.INVISIBLE);
			holder.getView(R.id.lin1).setVisibility(View.VISIBLE);
		} else {
			holder.getView(R.id.lin1).setVisibility(View.INVISIBLE);
			text = (TextView) holder.getView(R.id.text4);
			holder.setText(R.id.text3, "失败");
			holder.getView(R.id.lin).setVisibility(View.VISIBLE);
		}

		if (t.process_type == 2 && t.handle_time == 0) {
			TextView text3 = (TextView) holder.getView(R.id.text3);
			if (t.is_success == 1) {
				text = (TextView) holder.getView(R.id.text2);
				text3.setText("");
				holder.getView(R.id.lin).setVisibility(View.INVISIBLE);
				holder.getView(R.id.lin1).setVisibility(View.VISIBLE);
			} else {
				holder.getView(R.id.lin1).setVisibility(View.INVISIBLE);
				text = (TextView) holder.getView(R.id.text4);
				text3.setText("处理中");
				holder.getView(R.id.lin).setVisibility(View.VISIBLE);
			}

		}

		if (t.amount < 0) {
			text.setTextColor(ContextCompat.getColor(activity,R.color.red_text_color));
			text.setText("" + StringTools.formatFloatNumber(t.amount));
		} else {
			text.setTextColor(ContextCompat.getColor(activity,R.color.green_color_text));
			text.setText("+" + StringTools.formatFloatNumber(t.amount));
			if (t.type == 1 && t.amount == 0 && t.donate_money > 0) {
				text.setText("+" + StringTools.formatFloatNumber(t.donate_money));
			}

		}

		holder.getConvertView().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (in != null) {
					in.DoSomeThing(t);
				}
			}
		});

	}
}
